/*
 * ClassUtils.java - ScriptME
 * 
 * Copyright (c) 2009 Cesar Henriques <cesar at alttab.com.ar>.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v2.1
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * 
 * Based on FESI Project
 * 
 * Contributors:
 * 	Jean-Marc Lugrin - initial API and implementation
 * 	Cesar Henriques <cesar at alttab.com.ar> - J2ME Porting and Extensions
 */
package org.scriptme.util;

/**
 * <p>
 * ClassUtils
 * </p>.
 * 
 * @author Cesar
 */
public class ClassUtils {

	/** The Constant INTEGER_TYPE. */
	public static final int INTEGER_TYPE = 0;

	/** The Constant SHORT_TYPE. */
	public static final int SHORT_TYPE = 1;

	/** The Constant BYTE_TYPE. */
	public static final int BYTE_TYPE = 2;

	/** The Constant LONG_TYPE. */
	public static final int LONG_TYPE = 3;

	/** The Constant FLOAT_TYPE. */
	public static final int FLOAT_TYPE = 4;

	/** The Constant DOUBLE_TYPE. */
	public static final int DOUBLE_TYPE = 5;

	/** The Constant BOOLEAN_TYPE. */
	public static final int BOOLEAN_TYPE = 6;

	/** The Constant CHARACTER_TYPE. */
	public static final int CHARACTER_TYPE = 7;

	/**
	 * Gets the component type.
	 * 
	 * @param t
	 *            the t
	 * 
	 * @return the component type
	 */
	public static int getComponentType(Class t) {
		try {
			if (t.isInstance(Byte.class.newInstance()))
				return BYTE_TYPE;

			if (t.isInstance(Character.class.newInstance()))
				return CHARACTER_TYPE;

			if (t.isInstance(Short.class.newInstance()))
				return SHORT_TYPE;

			if (t.isInstance(Integer.class.newInstance()))
				return INTEGER_TYPE;

			if (t.isInstance(Long.class.newInstance()))
				return LONG_TYPE;

			if (t.isInstance(Float.class.newInstance()))
				return FLOAT_TYPE;

			if (t.isInstance(Double.class.newInstance()))
				return DOUBLE_TYPE;

			if (t.isInstance(Boolean.class.newInstance()))
				return BOOLEAN_TYPE;
		} catch (InstantiationException ex) {
			ex.printStackTrace();
		} catch (IllegalAccessException ex) {
			ex.printStackTrace();
		}
		return -1;
	}
}
